home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / wattcp / src / pcbsd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  1.8 KB  |  93 lines

  1. #include"capalloc.h"
  2. #include"capstdio.h"
  3. #include <copyright.h>
  4. #include <stdio.h>
  5. #include <wattcp.h>
  6. #include <stdlib.h>    /* itoa */
  7. #include <string.h>
  8. #include <elib.h>
  9.  
  10. /*
  11.  * PCBSD - provide some typical BSD UNIX functionality
  12.  * Erick Engelke, Feb 22, 1991
  13.  */
  14.  
  15. /*
  16.  * chk_socket - determine whether a real socket or not
  17.  *
  18.  */
  19. _chk_socket( tcp_Socket *s )
  20. {
  21.     if ( s->ip_type == TCP_PROTO ) {
  22.     if ( s->state <= tcp_StateCLOSED)    /* skips invalid data */
  23.         return( 2 );
  24.     }
  25.     if ( s->ip_type == UDP_PROTO ) return( 1 );
  26.     return( 0 );
  27. }
  28.  
  29. char *inet_ntoa( char *s, longword x )
  30. {
  31.  
  32.     itoa( x >> 24, s, 10 );
  33.     strcat( s, ".");
  34.     itoa( (x >> 16) & 0xff, strchr( s, 0), 10);
  35.     strcat( s, ".");
  36.     itoa( (x >> 8) & 0xff, strchr( s, 0), 10);
  37.     strcat( s, ".");
  38.     itoa( (x) & 0xff, strchr( s, 0), 10);
  39.     return( s );
  40. }
  41.  
  42. longword inet_addr( char *s )
  43. {
  44.     return( isaddr( s ) ? aton( s ) : 0 );
  45. }
  46.  
  47. char *sockerr( tcp_Socket *s )
  48. {
  49.     if ( strlen( s->err_msg ) < 80 )
  50.     return( s->err_msg );
  51.     return( NULL );
  52. }
  53.  
  54. static char *sock_states[] = {
  55.     "Listen","SynSent","SynRec","Established","FinWt1","FinWt2","ClosWt","LastAck"
  56.     "TmWt","Closed"};
  57.  
  58. char *sockstate( tcp_Socket *s )
  59. {
  60.     switch ( _chk_socket( s )) {
  61.        case  1 : return( "UDP Socket" );
  62.        case  2 : return( sock_states[ s->state ] );
  63.        default : return( "Not an active socket");
  64.     }
  65. }
  66. longword gethostid()
  67. {
  68.     return( my_ip_addr );
  69. }
  70.  
  71. longword sethostid( longword ip )
  72. {
  73.     return( my_ip_addr = ip );
  74. }
  75.  
  76. word ntohs( word a )
  77. {
  78.     return( intel16(a) );
  79. }
  80. word htons( word a )
  81. {
  82.     return( intel16(a) );
  83. }
  84. longword ntohl( longword x )
  85. {
  86.     return( intel( x ));
  87. }
  88. longword htonl( longword x )
  89. {
  90.     return( intel( x ));
  91. }
  92.  
  93.